package com.ilancuo.thinkinjava.chapter_21;

import java.util.concurrent.TimeUnit;

/**
 * Created by ilancuo on 2018/8/12.
 */
class ADaemon implements Runnable {

    @Override
    public void run() {
        try {
            System.out.println("Starting ADaemon");
            TimeUnit.SECONDS.sleep(1);
        } catch (InterruptedException e) {
            System.out.println("Exiting via InterruptedException");
        } finally {
            System.out.println("This should always run?");
        }
    }
}

public class DaemonsDontRunFinally {
    public static void main(String[] args) {
        Thread t = new Thread(new ADaemon());
        t.setDaemon(true); //加上这句代码,finally{}模块的代码不会执行;不加的话才会执行
        t.start();
    }
}
